﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using DTO.Models;
using CIT.Helper;
using DTO;

namespace CIT.Controllers
{
    public class SearchController : Controller
    {
        //
        // GET: /Search/

        public ActionResult Index(string id, int? page)
        {
            if (string.IsNullOrEmpty(id))
                return View("Error");           

            DataRepository dr = new DataRepository();
            var searchResult = dr.MediaProvider.GetAllMediaOutBySearchText(id);
            
            var model = new PaginatedList<MEDIA>(searchResult, page ?? 0, Common.pagesize);
            if (model.TotalCount == 0)
                ViewData["ResultCount"] = 0;
            else
            {
                ViewData["ResultCount"] = model.TotalCount;
                ViewData["SearchText"] = id;
            }

            return View(model);
           
        }

    }
}
